package com.xms.plugin.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.datacore.service.FinderService;
import com.xms.plugin.entity.EntityPlugin;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author migo
 * @since 2021-10-15
 */
@CacheConfig(cacheNames = "entityplugin", keyGenerator = "CacheKeyGenerator")
@Service
public class EntityPluginFinderService extends FinderService<EntityPlugin> implements IEntityPluginFinderService {

    @Cacheable(condition="#id != null")
    @Override
    public EntityPlugin getById(UUID id) {
        return super.getById(id);
    }

    @Cacheable(condition="#idList != null && #idList.size() > 0")
    @Override
    public List<EntityPlugin> getByIds(Collection<UUID> idList) {
        return super.listByIds(idList);
    }

    //@Cacheable()
    @Override
    public EntityPlugin getOne(Wrapper<EntityPlugin> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Cacheable()
    @Override
    public int count() {
        return super.count();
    }

    //@Cacheable()
    @Override
    public int count(Wrapper<EntityPlugin> queryWrapper) {
        return super.count(queryWrapper);
    }

    //@Cacheable()
    @Override
    public List<EntityPlugin> list(Wrapper<EntityPlugin> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<EntityPlugin> all() {
        return super.list();
    }

    @Cacheable(condition="#entityId != null")
    @Override
    public List<EntityPlugin> getByEntityId(UUID entityId) {
        LambdaQueryWrapper<EntityPlugin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EntityPlugin::getEntityid, entityId)
                .orderByAsc(EntityPlugin::getProcessorder);
        return super.list(queryWrapper);
    }

    @Cacheable(condition="#entityId != null")
    @Override
    public List<EntityPlugin> getByEntityId(UUID entityId, int eventCode) {
        LambdaQueryWrapper<EntityPlugin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EntityPlugin::getEntityid, entityId).eq(EntityPlugin::getEventcode, eventCode)
                .orderByAsc(EntityPlugin::getProcessorder);
        return super.list(queryWrapper);
    }

    @Cacheable(condition="#entityId != null && #objectId != null")
    @Override
    public List<EntityPlugin> getByObjectId(UUID entityId, UUID objectId, int eventCode, int typeCode) {
        LambdaQueryWrapper<EntityPlugin> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EntityPlugin::getEntityid, entityId)
                .eq(EntityPlugin::getEventcode, eventCode)
                .eq(EntityPlugin::getTypecode, typeCode)
                .orderByAsc(EntityPlugin::getProcessorder);
        return super.list(queryWrapper);
    }
}
